﻿﻿<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>骡窝窝问答</title>
    <meta name="viewport"
          content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui,viewport-fit=cover">
    <meta name="format-detection" content="telephone=no,address=no">

    <link href="css/mobile+css+head_mobile+css+ui^yvw^1526627473.css" rel="stylesheet" type="text/css">
    <link href="css/new_ask2016.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js" ></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem('user'));
            $('.btn-que').click(function () {
                if(user){
                window.location.href='/mine/editQuestions.html'
                }else {
                    $(document).dialog({
                        content: '请先登录',
                        autoClose: 1500,
                    });
                }
            })

            //搜索框回车事件
            var val= $('.searchBtn').val();
            $(".searchBtn").keydown(function (e) {
                if (e.keyCode == 13) {
                    //获取关键字搜索
                    val= $('.searchBtn').val();
                    console.log(val);
                    if(val ){
                        queryk();
                    }
                }
            });

            function queryk() {
                $('#queryFrom').ajaxForm(function (data) {
                    $.merge(questionArrk,data.list);
                    var json = { list:questionArrk};
                    //分页查询问题
                    $("#questions").renderValues(json,{
                        getHref:function (item,value) {
                            var href = $(item).data("href");
                            $(item).attr("href", href + value);
                        },
                        getAnswerNum:function (item, value) {
                            $(item).html(value.length)
                        }
                    });
                    pagesk = data.pages;
                });
                currentPagek ++;
            }


            var currentPage = 1;
            var currentPagek = 1;
            var pages;
            var pagesk;
            var questionArr = [];
            var questionArrk = [];
            function query() {
                $.get("/questions",{keyword:val,currentPage:currentPage},function (data) {

                    $.merge(questionArr,data.list);
                    var json = { list:questionArr};
                    //分页查询问题
                    $("#questions").renderValues(json,{
                        getHref:function (item,value) {
                            var href = $(item).data("href");
                            $(item).attr("href", href + value);
                        },
                        getAnswerNum:function (item, value) {
                            $(item).html(value.length)
                        }
                    });

                    pages = data.pages;
                });
                currentPage ++;
            }

            if(!val){
                query();
            }

            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop() >= $(document).height()-1) {
                    if (!val && currentPage <= pages) {
                        query();
                    }else if(val && currentPagek <= pagesk){
                        queryk();
                    }else {
                        $(document).dialog({
                            type : 'notice',
                            infoText: '小伙子,挺会滚的嘛!',
                            autoClose: 1500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });


        })
    </script>

    <style>
        .app {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
        }
    </style>
</head>
<body style="background-color: #cfcece">
<div id="pos38"></div>
<header class="search-head">
    <div class="row nav-search" style="background-color: #5a5959">
        <div class="col-3">
            <a href="/index.html">
                <span><i class="fa fa-chevron-left fa-2x" style="color: white"></i></span>
            </a>
        </div>
        <div class="col-9">
            <div  class="col-8">
                <h4 style="color: white">旅途问答</h4>
            </div>
        </div>
    </div>
</header>
<section class="ans-list" >
    <div class="_j_pager_box">
        <div  class="col-12">
            <form id="queryFrom" action="/questions" method="post">
                <input type="hidden" name="currentPage" value="1">
                <input type="text" class="form-control searchBtn" name="keyword" placeholder="搜索问题">
            </form>
        </div>
    </div>
</section>

<section class="ans-list" id="questions">
        <div  >
            <ul class="_j_pager_box"  render-loop="list">
                <li>
                    <a data-href="/answer.html?id=" render-key="list.id" render-fun="getHref">
                        <h2 render-html="list.title"></h2>
                        <div class="clearfix">
                            <div class="user-img clearfix" data-uid="46376914">
                                <p>
                                    <img render-src="list.user.headImgUrl">
                                </p>
                                <span  render-html="list.user.nickName"></span>
                                <span>发布于</span>
                                <span class="comment-date" render-html="list.releaseTime"></span>
                            </div>
                            <div class="ans-nr">
                                <div class="clearfix" >
                                    <div class="pic">
                                        <img render-src="list.coverUrl">
                                    </div>
                                    <div >
                                        <p render-html="list.content" >
                                        </p>
                                    </div>
                                </div>
                                <div class="clearfix">
                                    <span class="fl-l" render-html="list.region.name"></span>
                                    <span class="fl-r">
                                        <b render-html="list.pageViews"></b>次浏览
                                        <b id="answerNum" render-fun="getAnswerNum" render-key="list.answers"></b>次回答
                                        <b render-html="list.likeNum"></em></b><em>人顶</em>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</section>
<br/>
<br/>
<br/>

<section class="askfoot">
    <a data-href="/mine/editQuestions.html" class="btn-que" style="background-color: #5a5959"><i></i>
        我要提问
    </a>
</section>


</body>
</html>